<meta title="移动推送" />
<div class="p">
    <div class="row">
        <div class="col-md-6">
            <div class="panel panel-warning">
                <div class="panel-heading">
                    移动推送
                </div>
                <div class="panel-body">
                    <form class="form-horizontal" s="form,valid"
                          action="/api/mobile-push/page"
                          method="post"
                          id="pagePushForm">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">用户ID</label>
                            <div class="col-sm-10">
                                <input autocomplete="off" type="number" class="form-control" name="account" placeholder="不填写则代表推送给所有用户"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">平台</label>
                            <div class="col-sm-10 form-inline">
                                <label class="form-control" ><input autocomplete="off" type="checkbox" checked value="true" name="ios" /> Ios</label>
                                <label class="form-control" ><input autocomplete="off" type="checkbox" checked value="true" name="android" /> Android</label>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">标题</label>
                            <div class="col-sm-10">
                                <input autocomplete="off" type="text" class="form-control" name="title"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">内容</label>
                            <div class="col-sm-10">
                                <textarea class="form-control" name="content" s-valid-error="require()" style="width: 100%; height: 300px;"></textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">页面</label>
                            <div class="col-sm-10">
                                <select class="form-control" s="select" id="pageSelect" s-build="S.get('/api/enum/valuesMap/core.operation.center.domain.Page')" name="page"></select>
                            </div>
                        </div>
                    </form>
                    <form class="form-horizontal">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">页面参数</label>
                            <div class="col-sm-10" id="pageParams" s="window">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-10">
                                <button type="button" s-click="pushPage()" class="btn btn-default">推送</button>
                            </div>
                        </div>
                    </form>

                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    function pushPage() {
        S.confirm("确认推送吗").done(function() {

            $pagePushForm.validate().done(function() {
                $pageParams.getParams().done(function(params) {
                    var obj = Smart.serializeToObject($pagePushForm.node);
                    obj.params = params;
                    S.post("/api/mobile-push/page", obj).done(function() {
                        S.toast("推送成功", "success");
                    })
                })
            })
        })
    }

    $pageSelect.node.change(function () {
        var val = $(this).val();
        var paramData = {}
        $pageParams.load("/operation-center/params_" + val + ".html", {params: {}})
    })

    S.on("s-ready", function () {
        $pageSelect.node.change();
    })
    function getPageTitle() {
        return $pageSelect.node.find("option[value='" + $pageSelect.node.val() + "']").text();
    }

</script>